var ctx = $("#ctx").val();
$(function () {
    //搜索框展开的时候回车搜索
    /*$(document).keyup(function (event) {
        if (event.keyCode == 13) {
            $("#search-qq").trigger("click");
        }
    });*/
    dataList();
});

function dataList() {
    $.ajax({
        url: ctx + "/log/ajaxList",
        type: "GET",
        success: function (data) {
            if (data.code == 0) {
                $(".dataList").html("");
                var list = data.data;
                if (list.length > 0) {
                    $.each(list, function (index, value) {
                        var tbody = "<tr>" +
                            "<td>" + formatData(value.lid) + "</td>" +
                            "<td>" + formatData(value.uid) + "</td>" +
                            "<td>" + formatData(value.username) + "</td>" +
                            "<td>" + formatData(value.note) + "</td>" +
                            "<td>" + getLink(value.note, value.num) + "</td>" +
                            "<td>" + formatData(value.ip) + "</td>" +
                            "<td>" + formatData(value.createDate) + "</td>" +
                            "</tr>";
                        $(".dataList").append(tbody);
                    })
                } else {
                    $(".dataList").append("<tr><td colspan='7' style='text-align: center'>无数据</td></tr>");
                }
                mdui.mutation();
            } else {
                mdui.snackbar({
                    message: data.msg,
                    position: "top"
                });
            }
            $(".mdui-progress").css("display", "none");
        }
    })
}

function getLink(note, num) {
    var result = "<a target='_blank' href='" + ctx;
    if (note == "查询QQ") {
        result += "/search/qq?qq=";
    } else if (note == "查询群号") {
        result += "/search/group?qun=";
    } else if (note == "查询群信息") {
        result += "/search/quninfo?qun=";
    } else {
        return formatData(num);
    }
    result += formatData(num) + "'>" + formatData(num) + "</a>";
    return result;
}

function formatData(data) {
    if (data == null) {
        return "";
    } else {
        return data;
    }
}